package com.tea.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tea.Model.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * 用户Mapper接口
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {
    
    /**
     * 根据openId查询用户是否存在
     * @param openId 微信小程序openId
     * @return 用户数量
     */
    @Select("SELECT COUNT(*) FROM user WHERE open_id = #{openId} AND deleted = 0 AND status = 1")
    int countByOpenId(String openId);
    
    /**
     * 根据openId查询用户信息
     * @param openId 微信小程序openId
     * @return 用户信息
     */
    @Select("SELECT * FROM user WHERE open_id = #{openId} AND deleted = 0")
    User selectByOpenId(String openId);
}
